package com.example.project.webControlleer;

import com.example.project.dao.UserDAO;
import com.example.project.pojo.User;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

@Controller
@RequestMapping("web")
public class WebLoginController {
    @RequestMapping("login")
    public String login() {
        return "web/login";
    }

    @RequestMapping("loginCheck")
    public String loginCheck(User user, HttpSession httpSession ) {
        UserDAO userDAO = new UserDAO();
        User user1 = userDAO.login(user);
        if (user1.getUserPhone().isEmpty()) {
            return "redirect:/web/login?msg=1";
        }
        httpSession.setAttribute("user", user1);
        return "redirect:/web/index";
    }
}

